﻿using Niusys.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate.Linq;

namespace Niusys.Repostories
{
    public interface IUserRepository
    {
        User GetUser(Guid userId);
        User GetUserByLoginName(string loginName);

        void AddUser(User user);
    }

    public class UserRepository : BaseRepository, IUserRepository
    {
        public void AddUser(User user)
        {
            Session.Persist(user);
            Session.Flush();
        }

        public User GetUser(Guid userId)
        {
            return Session.Get<User>(userId);
        }

        public User GetUserByLoginName(string loginName)
        {
            return Session.QueryOver<User>().Where(x => x.LoginName == loginName).SingleOrDefault();
        }
    }
}
